﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar.BusinessObjects;

namespace SLControlLibrary.Resources.Controls.Calendar.OutlookCalendar
{
    public class ucDayContentItem : SLControlLibrary.Resources.Controls.Calendar.ucContentControl
    {
        #region Dependency Variables
        private static readonly DependencyProperty MouseOverOpacityProperty = DependencyProperty.Register("MouseOverOpacity", typeof(double), typeof(ucDayContentItem), new PropertyMetadata(0D));
        private static readonly DependencyProperty HasAppointmentProperty = DependencyProperty.Register("HasAppointment", typeof(Visibility), typeof(ucDayContentItem), new PropertyMetadata(Visibility.Visible));
        private static readonly DependencyProperty DayContentForegroundProperty = DependencyProperty.Register("DayContentForeground", typeof(Brush), typeof(ucDayContentItem), new PropertyMetadata(new SolidColorBrush(Colors.White), new PropertyChangedCallback(DayContentForeground_Changed)));
        private static readonly DependencyProperty DayContentHoverBorderBrushProperty = DependencyProperty.Register("DayContentHoverBorderBrush", typeof(Brush), typeof(ucDayContentItem), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#5D8CC9"), new PropertyChangedCallback(DayContentHoverBorderBrush_Changed)));
        private static readonly DependencyProperty DayContentHoverBackgroundProperty = DependencyProperty.Register("DayContentHoverBackground", typeof(Brush), typeof(ucDayContentItem), new PropertyMetadata(SLControlLibrary.Resources.Common.Utility.ConvertStringToColor("#10000000"), new PropertyChangedCallback(DayContentHoverBackground_Changed)));
        private static readonly DependencyProperty DayContentHoverBorderThicknessProperty = DependencyProperty.Register("DayContentHoverBorderThickness", typeof(Thickness), typeof(ucDayContentItem), new PropertyMetadata(new Thickness(1), new PropertyChangedCallback(DayContentHoverBorderThickness_Changed)));
        #endregion

        #region Dependency Properties
        public double MouseOverOpacity
        {
            get { return double.Parse(this.GetValue(MouseOverOpacityProperty).ToString()); }
            set { this.SetValue(MouseOverOpacityProperty, value); }
        }
        public Visibility HasAppointment
        {
            get { return (Visibility)this.GetValue(HasAppointmentProperty); }
            set { this.SetValue(HasAppointmentProperty, value); }
        }
        public Brush DayContentForeground
        {
            get { return (Brush)this.GetValue(DayContentForegroundProperty); }
            set { this.SetValue(DayContentForegroundProperty, value); }
        }
        public Brush DayContentHoverBorderBrush
        {
            get { return (Brush)this.GetValue(DayContentHoverBorderBrushProperty); }
            set { this.SetValue(DayContentHoverBorderBrushProperty, value); }
        }
        public Brush DayContentHoverBackground
        {
            get { return (Brush)this.GetValue(DayContentHoverBackgroundProperty); }
            set { this.SetValue(DayContentHoverBackgroundProperty, value); }
        }
        public Thickness DayContentHoverBorderThickness
        {
            get { return (Thickness)this.GetValue(DayContentHoverBorderThicknessProperty); }
            set { this.SetValue(DayContentHoverBorderThicknessProperty, value); }
        }
        #endregion

        #region Dependency Events
        #region DayContentForeground_Changed
        private static void DayContentForeground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayContentItem).OnDayContentForeground_Changed(e);
        }
        #endregion

        #region DayContentHoverBorderBrush_Changed
        private static void DayContentHoverBorderBrush_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayContentItem).OnDayContentHoverBorderBrush_Changed(e);
        }
        #endregion

        #region DayContentHoverBackground_Changed
        private static void DayContentHoverBackground_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayContentItem).OnDayContentHoverBackground_Changed(e);
        }
        #endregion

        #region DayContentHoverBorderThickness_Changed
        private static void DayContentHoverBorderThickness_Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            (sender as ucDayContentItem).OnDayContentHoverBorderThickness_Changed(e);
        }
        #endregion
        #endregion

        #region Event Variables
        public event EventHandler AddAppointment_Clicked;
        #endregion

        #region Constructor
        public ucDayContentItem()
        {
            DefaultStyleKey = typeof(ucDayContentItem);
        }
        #endregion

        #region Methods
        #region OnApplyTemplate
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            base.MouseEnter += new MouseEventHandler(brdRoot_MouseEnter);
            base.MouseLeave += new MouseEventHandler(brdRoot_MouseLeave);
            base.MouseDoubleClick += new MouseDblClickHandler(brd_MouseDoubleClick);
        }
        #endregion

        #region OnDayContentForeground_Changed
        protected virtual void OnDayContentForeground_Changed(DependencyPropertyChangedEventArgs e)
        {
            DayContentForeground = (Brush)e.NewValue;
        }
        #endregion

        #region OnDayContentHoverBorderBrush_Changed
        protected virtual void OnDayContentHoverBorderBrush_Changed(DependencyPropertyChangedEventArgs e)
        {
            DayContentHoverBorderBrush = (Brush)e.NewValue;
        }
        #endregion

        #region OnDayContentHoverBackground_Changed
        protected virtual void OnDayContentHoverBackground_Changed(DependencyPropertyChangedEventArgs e)
        {
            DayContentHoverBackground = (Brush)e.NewValue;
        }
        #endregion

        #region OnDayContentHoverBorderThickness_Changed
        protected virtual void OnDayContentHoverBorderThickness_Changed(DependencyPropertyChangedEventArgs e)
        {
            DayContentHoverBorderThickness = (Thickness)e.NewValue;
        }
        #endregion
        #endregion

        #region Events
        #region brdRoot_MouseLeave
        private void brdRoot_MouseLeave(object sender, MouseEventArgs e)
        {
            MouseOverOpacity = 0;
        }
        #endregion

        #region brdRoot_MouseEnter
        private void brdRoot_MouseEnter(object sender, MouseEventArgs e)
        {
            MouseOverOpacity = 1;
        }
        #endregion

        #region brdRoot_MouseLeftButtonUp
        private void brdRoot_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {            
        }
        #endregion

        #region brd_MouseDoubleClick
        void brd_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (HasAppointment == Visibility.Visible)
            {
                if (AddAppointment_Clicked != null)
                    AddAppointment_Clicked(this, null);
            }
        }
        #endregion
        #endregion
    }
}
